﻿Public Class DatePickerJS
    Public Overrides Function ToString() As String
        Dim s As String = ""

        s = s & "var datePickerDivID = ""datepicker"";" & vbcrlf
        s = s & "var iFrameDivID = ""datepickeriframe"";" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "var dayArrayMed = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');" & vbcrlf
        s = s & "var dayArrayShort = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');" & vbcrlf
        s = s & "var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');" & vbcrlf
        s = s & "var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');" & vbcrlf
        s = s & "var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');" & vbcrlf
        s = s & "var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "// these variables define the date formatting we're expecting and outputting." & vbcrlf
        s = s & "// If you want to use a different format by default, change the defaultDateSeparator" & vbcrlf
        s = s & "// and defaultDateFormat variables either here or on your HTML page." & vbcrlf
        s = s & "var defaultDateSeparator = ""/"";        // common values would be ""/"" or "".""" & vbcrlf
        s = s & "var defaultDateFormat = ""mdy""    // valid values are ""mdy"", ""dmy"", and ""ymd""" & vbcrlf
        s = s & "var dateSeparator = defaultDateSeparator;" & vbcrlf
        s = s & "var dateFormat = defaultDateFormat;" & vbcrlf
        s = s & "var showTime = false;" & vbcrlf
        s = s & "var currentHour;" & vbcrlf
        s = s & "var currentMinute;" & vbcrlf
        s = s & "var currentHalf;" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "function displayDatePicker(dateFieldName, dateOnly, displayBelowThisObject, dtFormat, dtSep)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "  var targetDateField = document.getElementsByName(dateFieldName).item(0);" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  var dt = getFieldDate(targetDateField.value );" & vbcrlf
        s = s & "  currentHour = dt.getHours();" & vbcrlf
        s = s & "  currentMinute = dt.getMinutes();" & vbcrlf
        s = s & "  " & vbcrlf
        s = s & "  if ( currentHour > 12 )" & vbcrlf
        s = s & "  {" & vbcrlf
        s = s & "    currentHalf = ""pm"";" & vbcrlf
        s = s & "    currentHour = currentHour - 12;" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & "  else" & vbcrlf
        s = s & "  {" & vbcrlf
        s = s & "    currentHalf = ""am"";" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & "  " & vbcrlf
        s = s & "  // if we weren't told what node to display the datepicker beneath, just display it" & vbcrlf
        s = s & "  // beneath the date field we're updating" & vbcrlf
        s = s & "  if (!displayBelowThisObject)" & vbcrlf
        s = s & "    displayBelowThisObject = targetDateField;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // if a date separator character was given, update the dateSeparator variable" & vbcrlf
        s = s & "  if (dtSep)" & vbcrlf
        s = s & "    dateSeparator = dtSep;" & vbcrlf
        s = s & "  else" & vbcrlf
        s = s & "    dateSeparator = defaultDateSeparator;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // if a date format was given, update the dateFormat variable" & vbcrlf
        s = s & "  if (dtFormat)" & vbcrlf
        s = s & "    dateFormat = dtFormat;" & vbcrlf
        s = s & "  else" & vbcrlf
        s = s & "    dateFormat = defaultDateFormat;" & vbcrlf
        s = s & "    " & vbcrlf
        s = s & "  " & vbcrlf
        s = s & "  if (dateOnly)" & vbcrlf
        s = s & "      showTime = false;" & vbcrlf
        s = s & "  else" & vbcrlf
        s = s & "      showTime = true;" & vbcrlf
        s = s & "        " & vbcrlf
        s = s & "  var x = displayBelowThisObject.offsetLeft;" & vbcrlf
        s = s & "  var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // deal with elements inside tables and such" & vbcrlf
        s = s & "  var parent = displayBelowThisObject;" & vbcrlf
        s = s & "  while (parent.offsetParent) {" & vbcrlf
        s = s & "    parent = parent.offsetParent;" & vbcrlf
        s = s & "    x += parent.offsetLeft;" & vbcrlf
        s = s & "    y += parent.offsetTop ;" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  drawDatePicker(targetDateField, x, y);" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "/**" & vbcrlf
        s = s & "Draw the datepicker object (which is just a table with calendar elements) at the" & vbcrlf
        s = s & "specified x and y coordinates, using the targetDateField object as the input tag" & vbcrlf
        s = s & "that will ultimately be populated with a date." & vbcrlf
        s = s & "" & vbcrlf
        s = s & "This function will normally be called by the displayDatePicker function." & vbcrlf
        s = s & "*/" & vbcrlf
        s = s & "function drawDatePicker(targetDateField, x, y)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "  var dt = getFieldDate(targetDateField.value );" & vbcrlf
        s = s & "    " & vbcrlf
        s = s & "  // the datepicker table will be drawn inside of a <div> with an ID defined by the" & vbcrlf
        s = s & "  // global datePickerDivID variable. If such a div doesn't yet exist on the HTML" & vbcrlf
        s = s & "  // document we're working with, add one." & vbcrlf
        s = s & "  if (!document.getElementById(datePickerDivID)) {" & vbcrlf
        s = s & "    // don't use innerHTML to update the body, because it can cause global variables" & vbcrlf
        s = s & "    // that are currently pointing to objects on the page to have bad references" & vbcrlf
        s = s & "    //document.body.innerHTML += ""<div id='"" + datePickerDivID + ""' class='dpDiv'></div>"";" & vbcrlf
        s = s & "    var newNode = document.createElement(""div"");" & vbcrlf
        s = s & "    newNode.setAttribute(""id"", datePickerDivID);" & vbcrlf
        s = s & "    newNode.setAttribute(""class"", ""dpDiv"");" & vbcrlf
        s = s & "    newNode.setAttribute(""style"", ""visibility: hidden;"");" & vbcrlf
        s = s & "    document.body.appendChild(newNode);" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // move the datepicker div to the proper x,y coordinate and toggle the visiblity" & vbcrlf
        s = s & "  var pickerDiv = document.getElementById(datePickerDivID);" & vbcrlf
        s = s & "  pickerDiv.style.position = ""absolute"";" & vbcrlf
        s = s & "  pickerDiv.style.left = x + ""px"";" & vbcrlf
        s = s & "  pickerDiv.style.top = y + ""px"";" & vbcrlf
        s = s & "  pickerDiv.style.visibility = (pickerDiv.style.visibility == ""visible"" ? ""hidden"" : ""visible"");" & vbcrlf
        s = s & "  pickerDiv.style.display = (pickerDiv.style.display == ""block"" ? ""none"" : ""block"");" & vbcrlf
        s = s & "  pickerDiv.style.zIndex = 10000;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // draw the datepicker table" & vbcrlf
        s = s & "  refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth());" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "/**" & vbcrlf
        s = s & "This is the function that actually draws the datepicker calendar." & vbcrlf
        s = s & "*/" & vbcrlf
        s = s & "function refreshDatePicker(dateFieldName, year, month, day)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "  // if no arguments are passed, use today's date; otherwise, month and year" & vbcrlf
        s = s & "  // are required (if a day is passed, it will be highlighted later)" & vbcrlf
        s = s & "  //alert(hour);" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "  var thisDay = new Date();" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  if ((month >= 0) && (year > 0)) {" & vbcrlf
        s = s & "    // year, month, day, hour, min, sec, ms" & vbcrlf
        s = s & "    thisDay = new Date(year, month, 1);" & vbcrlf
        s = s & "  } else {" & vbcrlf
        s = s & "    day = thisDay.getDate();" & vbcrlf
        s = s & "    thisDay.setDate(1);" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // the calendar will be drawn as a table" & vbcrlf
        s = s & "  // you can customize the table elements with a global CSS style sheet," & vbcrlf
        s = s & "  // or by hardcoding style and formatting elements below" & vbcrlf
        s = s & "  var crlf = ""\r\n"";" & vbcrlf
        s = s & "  var TABLE = ""<table cols=7 class='dpTable'>"" + crlf;" & vbcrlf
        s = s & "  var xTABLE = ""</table>"" + crlf;" & vbcrlf
        s = s & "  var TR = ""<tr class='dpTR'>"";" & vbcrlf
        s = s & "  var TR_title = ""<tr class='dpTitleTR'>"";" & vbcrlf
        s = s & "  var TR_days = ""<tr class='dpDayTR'>"";" & vbcrlf
        s = s & "  var TR_todaybutton = ""<tr class='dpTodayButtonTR'>"";" & vbcrlf
        s = s & "  var xTR = ""</tr>"" + crlf;" & vbcrlf
        s = s & "  var TD = ""<td class='dpTD' onMouseOut='this.className=\""dpTD\"";' onMouseOver=' this.className=\""dpTDHover\"";' "";    // leave this tag open, because we'll be adding an onClick event" & vbcrlf
        s = s & "  var TD_title = ""<td colspan=5 class='dpTitleTD'>"";" & vbcrlf
        s = s & "  var TD_buttons = ""<td class='dpButtonTD'>"";" & vbcrlf
        s = s & "  var TD_todaybutton = ""<td colspan=7 class='dpTodayButtonTD'>"";" & vbcrlf
        s = s & "  var TD_days = ""<td class='dpDayTD'>"";" & vbcrlf
        s = s & "  var TD_selected = ""<td class='dpDayHighlightTD' onMouseOut='this.className=\""dpDayHighlightTD\"";' onMouseOver='this.className=\""dpTDHover\"";' "";    // leave this tag open, because we'll be adding an onClick event" & vbcrlf
        s = s & "  var xTD = ""</td>"" + crlf;" & vbcrlf
        s = s & "  var DIV_title = ""<div class='dpTitleText'>"";" & vbcrlf
        s = s & "  var DIV_selected = ""<div class='dpDayHighlight'>"";" & vbcrlf
        s = s & "  var xDIV = ""</div>"";" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // start generating the code for the calendar table" & vbcrlf
        s = s & "  var html = TABLE;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // this is the title bar, which displays the month and the buttons to" & vbcrlf
        s = s & "  // go back to a previous month or forward to the next month" & vbcrlf
        s = s & "  html += TR_title;" & vbcrlf
        s = s & "  html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, ""&lt;"") + xTD;" & vbcrlf
        s = s & "  html += TD_title + DIV_title + monthArrayLong[ thisDay.getMonth()] + "" "" + thisDay.getFullYear() + xDIV + xTD;" & vbcrlf
        s = s & "  html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, ""&gt;"") + xTD;" & vbcrlf
        s = s & "  html += xTR;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // this is the row that indicates which day of the week we're on" & vbcrlf
        s = s & "  html += TR_days;" & vbcrlf
        s = s & "  for(i = 0; i < dayArrayShort.length; i++)" & vbcrlf
        s = s & "    html += TD_days + dayArrayShort[i] + xTD;" & vbcrlf
        s = s & "  html += xTR;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // now we'll start populating the table with days of the month" & vbcrlf
        s = s & "  html += TR;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // first, the leading blanks" & vbcrlf
        s = s & "  for (i = 0; i < thisDay.getDay(); i++)" & vbcrlf
        s = s & "    html += TD + ""&nbsp;"" + xTD;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // now, the days of the month" & vbcrlf
        s = s & "  do {" & vbcrlf
        s = s & "    dayNum = thisDay.getDate();" & vbcrlf
        s = s & "    TD_onclick = "" onclick=\""updateDateField('"" + dateFieldName + ""', '"" + getDateString(thisDay) + ""');\"">"";" & vbcrlf
        s = s & "    " & vbcrlf
        s = s & "    if (dayNum == day)" & vbcrlf
        s = s & "      html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;" & vbcrlf
        s = s & "    else" & vbcrlf
        s = s & "      html += TD + TD_onclick + dayNum + xTD;" & vbcrlf
        s = s & "    " & vbcrlf
        s = s & "    // if this is a Saturday, start a new row" & vbcrlf
        s = s & "    if (thisDay.getDay() == 6)" & vbcrlf
        s = s & "      html += xTR + TR;" & vbcrlf
        s = s & "    " & vbcrlf
        s = s & "    // increment the day" & vbcrlf
        s = s & "    thisDay.setDate(thisDay.getDate() + 1);" & vbcrlf
        s = s & "  } while (thisDay.getDate() > 1)" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // fill in any trailing blanks" & vbcrlf
        s = s & "  if (thisDay.getDay() > 0) {" & vbcrlf
        s = s & "    for (i = 6; i > thisDay.getDay(); i--)" & vbcrlf
        s = s & "      html += TD + ""&nbsp;"" + xTD;" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & "  html += xTR;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // add a button to allow the user to easily return to today, or close the calendar" & vbcrlf
        s = s & "  var today = new Date();" & vbcrlf
        s = s & "  //var todayString = ""Today is "" + dayArrayMed[today.getDay()] + "", "" + monthArrayMed[ today.getMonth()] + "" "" + today.getDate();" & vbcrlf
        s = s & "  html += TR_todaybutton + TD_todaybutton;" & vbcrlf
        s = s & "  html += ""<table width='100%'><tr><td align='center'>"";" & vbcrlf
        s = s & "  //<button class='dpTodayButton' onClick='refreshDatePicker(\"""" + dateFieldName + ""\"");'>today</button>" & vbcrlf
        s = s & "  if ( !showTime )" & vbcrlf
        s = s & "  {" & vbcrlf
        s = s & "    html += ""<div class=dpTodayButton>Time</div> <select name='pcgdpHour' ID='pcgdpHour'  onChange='pcgdpHourChange(this);'>"";" & vbcrlf
        s = s & "    for ( i = 1; i < 12; i++)" & vbcrlf
        s = s & "    {" & vbcrlf
        s = s & "      html += ""<option""" & vbcrlf
        s = s & "      if (i == currentHour) " & vbcrlf
        s = s & "        html += "" selected""" & vbcrlf
        s = s & "      html += "">"" + i + ""</option>"";" & vbcrlf
        s = s & "    }" & vbcrlf
        s = s & "  " & vbcrlf
        s = s & "    html += ""</select> : <select name='pcgdpMinute' ID='pcgdpMinute' onChange='pcgdpMinuteChange(this);'>""" & vbcrlf
        s = s & "    for ( i = 0; i < 59; i++)" & vbcrlf
        s = s & "    {" & vbcrlf
        s = s & "      html += ""<option""" & vbcrlf
        s = s & "      if (i == currentMinute) " & vbcrlf
        s = s & "        html += "" selected""" & vbcrlf
        s = s & "      html += "">"" " & vbcrlf
        s = s & "      if ( i < 10 )" & vbcrlf
        s = s & "      {" & vbcrlf
        s = s & "        html += '0';      " & vbcrlf
        s = s & "      }" & vbcrlf
        s = s & "      html += i; " & vbcrlf
        s = s & "      html += ""</option>"";" & vbcrlf
        s = s & "    }" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "    html += ""</select> "";" & vbcrlf
        s = s & "    " & vbcrlf
        s = s & "    html += ""<select name='pcgdpAMPM' ID='pcgdpAMPM' onChange='pcgdpAMPMChange(this);'>"";" & vbcrlf
        s = s & "    html += ""<option"";" & vbcrlf
        s = s & "    if ( currentHalf == ""am"" )" & vbcrlf
        s = s & "        html += "" selected"";" & vbcrlf
        s = s & "    html += "">am</option>"";" & vbcrlf
        s = s & "        html += ""<option"";" & vbcrlf
        s = s & "    if ( currentHalf == ""pm"" )" & vbcrlf
        s = s & "        html += "" selected"";" & vbcrlf
        s = s & "    html += "">pm</option>"";" & vbcrlf
        s = s & "    html += ""</select>"";" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & "      " & vbcrlf
        s = s & "  html += ""</td>"";" & vbcrlf
        s = s & "  html += ""<td align='right'><button class='dpTodayButton' onClick='updateDateField(\"""" + dateFieldName + ""\"");'>x</button></td></tr></table>"";" & vbcrlf
        s = s & "  html += xTD + xTR;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // and finally, close the table" & vbcrlf
        s = s & "  html += xTABLE;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  document.getElementById(datePickerDivID).innerHTML = html;" & vbcrlf
        s = s & "  // add an ""iFrame shim"" to allow the datepicker to display above selection lists" & vbcrlf
        s = s & "  adjustiFrame();" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "function pcgdpHourChange(cbo)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "    currentHour = cbo.options[cbo.selectedIndex].text;" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "function pcgdpMinuteChange(cbo)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "    currentMinute = cbo.options[cbo.selectedIndex].text;" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "function pcgdpAMPMChange(cbo)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "    currentHalf = cbo.options[cbo.selectedIndex].text;" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "/**" & vbcrlf
        s = s & "Convenience function for writing the code for the buttons that bring us back or forward" & vbcrlf
        s = s & "a month." & vbcrlf
        s = s & "*/" & vbcrlf
        s = s & "function getButtonCode(dateFieldName, dateVal, adjust, label)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "  var newMonth = (dateVal.getMonth () + adjust) % 12;" & vbcrlf
        s = s & "  var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);" & vbcrlf
        s = s & "  if (newMonth < 0) {" & vbcrlf
        s = s & "    newMonth += 12;" & vbcrlf
        s = s & "    newYear += -1;" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  return ""<button class='dpButton' onClick='refreshDatePicker(\"""" + dateFieldName + ""\"", "" + newYear + "", "" + newMonth + "");'>"" + label + ""</button>"";" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "/**" & vbcrlf
        s = s & "Convert a JavaScript Date object to a string, based on the dateFormat and dateSeparator" & vbcrlf
        s = s & "variables at the beginning of this script library." & vbcrlf
        s = s & "*/" & vbcrlf
        s = s & "function getDateString(dateVal)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "  var dayString = ""00"" + dateVal.getDate();" & vbcrlf
        s = s & "  var monthString = ""00"" + (dateVal.getMonth()+1);" & vbcrlf
        s = s & "  dayString = dayString.substring(dayString.length - 2);" & vbcrlf
        s = s & "  monthString = monthString.substring(monthString.length - 2);" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  switch (dateFormat) {" & vbcrlf
        s = s & "    case ""dmy"" :" & vbcrlf
        s = s & "      return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();" & vbcrlf
        s = s & "    case ""ymd"" :" & vbcrlf
        s = s & "      return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;" & vbcrlf
        s = s & "    case ""mdy"" :" & vbcrlf
        s = s & "    default :" & vbcrlf
        s = s & "      return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "/**" & vbcrlf
        s = s & "Convert a string to a JavaScript Date object." & vbcrlf
        s = s & "*/" & vbcrlf
        s = s & "function getFieldDate(dateString)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "  var dateVal;" & vbcrlf
        s = s & "  var dArray;" & vbcrlf
        s = s & "  var d, m, y;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  try {" & vbcrlf
        s = s & "    dArray = splitDateString(dateString);" & vbcrlf
        s = s & "    if (dArray) {" & vbcrlf
        s = s & "      switch (dateFormat) {" & vbcrlf
        s = s & "        case ""dmy"" :" & vbcrlf
        s = s & "          d = parseInt(dArray[0], 10);" & vbcrlf
        s = s & "          m = parseInt(dArray[1], 10) - 1;" & vbcrlf
        s = s & "          y = parseInt(dArray[2], 10);" & vbcrlf
        s = s & "          break;" & vbcrlf
        s = s & "        case ""ymd"" :" & vbcrlf
        s = s & "          d = parseInt(dArray[2], 10);" & vbcrlf
        s = s & "          m = parseInt(dArray[1], 10) - 1;" & vbcrlf
        s = s & "          y = parseInt(dArray[0], 10);" & vbcrlf
        s = s & "          break;" & vbcrlf
        s = s & "        case ""mdy"" :" & vbcrlf
        s = s & "        default :" & vbcrlf
        s = s & "          d = parseInt(dArray[1], 10);" & vbcrlf
        s = s & "          m = parseInt(dArray[0], 10) - 1;" & vbcrlf
        s = s & "          y = parseInt(dArray[2], 10);" & vbcrlf
        s = s & "          break;" & vbcrlf
        s = s & "      }" & vbcrlf
        s = s & "      dateVal = new Date(y, m, d);" & vbcrlf
        s = s & "    } else if (dateString) {" & vbcrlf
        s = s & "      dateVal = new Date(dateString);" & vbcrlf
        s = s & "    } else {" & vbcrlf
        s = s & "      dateVal = new Date();" & vbcrlf
        s = s & "    }" & vbcrlf
        s = s & "  } catch(e) {" & vbcrlf
        s = s & "    dateVal = new Date();" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  return dateVal;" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "/**" & vbcrlf
        s = s & "Try to split a date string into an array of elements, using common date separators." & vbcrlf
        s = s & "If the date is split, an array is returned; otherwise, we just return false." & vbcrlf
        s = s & "*/" & vbcrlf
        s = s & "function splitDateString(dateString)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "//var x = Date.parse(dateString);" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "    //alert(x);" & vbcrlf
        s = s & "//    alert(',' + x.getMinutes());" & vbcrlf
        s = s & "//    alert(',3dc' + x.getYears());" & vbcrlf
        s = s & "    if (!showTime)" & vbcrlf
        s = s & "    {" & vbcrlf
        s = s & "        var xArray = dateString.split("" "");" & vbcrlf
        s = s & "        if (xArray)" & vbcrlf
        s = s & "        {" & vbcrlf
        s = s & "            if (xArray.length==3)" & vbcrlf
        s = s & "            {" & vbcrlf
        s = s & "                currentHalf = xArray[2];" & vbcrlf
        s = s & "                var xTime = xArray[1].split("":"");" & vbcrlf
        s = s & "                if (xTime)" & vbcrlf
        s = s & "                {" & vbcrlf
        s = s & "                    if (xTime.length==2)" & vbcrlf
        s = s & "                    {" & vbcrlf
        s = s & "                        currentHour = xTime[0];" & vbcrlf
        s = s & "                        currentMinute =xTime[1];" & vbcrlf
        s = s & "                    }" & vbcrlf
        s = s & "                }                " & vbcrlf
        s = s & "            }" & vbcrlf
        s = s & "            //alert('test');" & vbcrlf
        s = s & "            //alert(xArray.length);" & vbcrlf
        s = s & "        }" & vbcrlf
        s = s & "    }" & vbcrlf
        s = s & "  var dArray;" & vbcrlf
        s = s & "  if (dateString.indexOf(""/"") >= 0)" & vbcrlf
        s = s & "    dArray = dateString.split(""/"");" & vbcrlf
        s = s & "  else if (dateString.indexOf(""."") >= 0)" & vbcrlf
        s = s & "    dArray = dateString.split(""."");" & vbcrlf
        s = s & "  else if (dateString.indexOf(""-"") >= 0)" & vbcrlf
        s = s & "    dArray = dateString.split(""-"");" & vbcrlf
        s = s & "  else if (dateString.indexOf(""\\"") >= 0)" & vbcrlf
        s = s & "    dArray = dateString.split(""\\"");" & vbcrlf
        s = s & "  else" & vbcrlf
        s = s & "    dArray = false;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  return dArray;" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "function updateDateField(dateFieldName, dateString)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "  var targetDateField = document.getElementsByName(dateFieldName).item(0);" & vbcrlf
        s = s & "  " & vbcrlf
        s = s & "  if (dateString)" & vbcrlf
        s = s & "  {" & vbcrlf
        s = s & "    var ctlHour = document.getElementsByName(""pcgdpHour"").item(0);" & vbcrlf
        s = s & "    if (ctlHour) {" & vbcrlf
        s = s & "        dateString = dateString + ' ' + ctlHour.options[ctlHour.selectedIndex].text;" & vbcrlf
        s = s & "    }" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "    var pcgdpMinute = document.getElementsByName(""pcgdpMinute"").item(0);" & vbcrlf
        s = s & "    if (pcgdpMinute) {" & vbcrlf
        s = s & "        dateString = dateString + ':' + pcgdpMinute.options[pcgdpMinute.selectedIndex].text;" & vbcrlf
        s = s & "    }" & vbcrlf
        s = s & "        " & vbcrlf
        s = s & "    var pcgdpAMPM = document.getElementsByName(""pcgdpAMPM"").item(0);" & vbcrlf
        s = s & "    if (pcgdpAMPM) {" & vbcrlf
        s = s & "        dateString = dateString + ' ' + pcgdpAMPM.options[pcgdpAMPM.selectedIndex].text;" & vbcrlf
        s = s & "    }" & vbcrlf
        s = s & "        " & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "  if (dateString)" & vbcrlf
        s = s & "    targetDateField.value = dateString;" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  var pickerDiv = document.getElementById(datePickerDivID);" & vbcrlf
        s = s & "  pickerDiv.style.visibility = ""hidden"";" & vbcrlf
        s = s & "  pickerDiv.style.display = ""none"";" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  adjustiFrame();" & vbcrlf
        s = s & "  targetDateField.focus();" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  // after the datepicker has closed, optionally run a user-defined function called" & vbcrlf
        s = s & "  // datePickerClosed, passing the field that was just updated as a parameter" & vbcrlf
        s = s & "  // (note that this will only run if the user actually selected a date from the datepicker)" & vbcrlf
        s = s & "  if ((dateString) && (typeof(datePickerClosed) == ""function""))" & vbcrlf
        s = s & "    datePickerClosed(targetDateField);" & vbcrlf
        s = s & "}" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "" & vbcrlf
        s = s & "function adjustiFrame(pickerDiv, iFrameDiv)" & vbcrlf
        s = s & "{" & vbcrlf
        s = s & "  var is_opera = (navigator.userAgent.toLowerCase().indexOf(""opera"") != -1);" & vbcrlf
        s = s & "  if (is_opera)" & vbcrlf
        s = s & "    return;" & vbcrlf
        s = s & "  " & vbcrlf
        s = s & "  try {" & vbcrlf
        s = s & "    if (!document.getElementById(iFrameDivID)) {" & vbcrlf
        s = s & "      // don't use innerHTML to update the body, because it can cause global variables" & vbcrlf
        s = s & "      // that are currently pointing to objects on the page to have bad references" & vbcrlf
        s = s & "      //document.body.innerHTML += ""<iframe id='"" + iFrameDivID + ""' src='javascript:false;' scrolling='no' frameborder='0'>"";" & vbcrlf
        s = s & "      var newNode = document.createElement(""iFrame"");" & vbcrlf
        s = s & "      newNode.setAttribute(""id"", iFrameDivID);" & vbcrlf
        s = s & "      newNode.setAttribute(""src"", ""javascript:false;"");" & vbcrlf
        s = s & "      newNode.setAttribute(""scrolling"", ""no"");" & vbcrlf
        s = s & "      newNode.setAttribute (""frameborder"", ""0"");" & vbcrlf
        s = s & "      document.body.appendChild(newNode);" & vbcrlf
        s = s & "    }" & vbcrlf
        s = s & "    " & vbcrlf
        s = s & "    if (!pickerDiv)" & vbcrlf
        s = s & "      pickerDiv = document.getElementById(datePickerDivID);" & vbcrlf
        s = s & "    if (!iFrameDiv)" & vbcrlf
        s = s & "      iFrameDiv = document.getElementById(iFrameDivID);" & vbcrlf
        s = s & "    " & vbcrlf
        s = s & "    try {" & vbcrlf
        s = s & "      iFrameDiv.style.position = ""absolute"";" & vbcrlf
        s = s & "      iFrameDiv.style.width = pickerDiv.offsetWidth;" & vbcrlf
        s = s & "      iFrameDiv.style.height = pickerDiv.offsetHeight ;" & vbcrlf
        s = s & "      iFrameDiv.style.top = pickerDiv.style.top;" & vbcrlf
        s = s & "      iFrameDiv.style.left = pickerDiv.style.left;" & vbcrlf
        s = s & "      iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;" & vbcrlf
        s = s & "      iFrameDiv.style.visibility = pickerDiv.style.visibility ;" & vbcrlf
        s = s & "      iFrameDiv.style.display = pickerDiv.style.display;" & vbcrlf
        s = s & "    } catch(e) {" & vbcrlf
        s = s & "    }" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "  } catch (ee) {" & vbcrlf
        s = s & "  }" & vbcrlf
        s = s & " " & vbcrlf
        s = s & "}" & vbcrlf
        Return s
    End Function

End Class
